﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Windows.Threading;

namespace EnergyConsumptionMonitorSystem.MainWindowTabItem
{
    /// <summary>
    /// Interaction logic for MainWindowTabItem.xaml
    /// </summary>
    public partial class MainWindowTabItem : TabItem
    {
        public int HeaderMouseEnterTimerMilliseconds { get; set; }
        public event MouseEventHandler HeaderMouseEnterEvent;
        public event MouseEventHandler HeaderMouseLeaveEvent;
        public event MouseButtonEventHandler PreviewHeaderMouseLeftButtonDownEvent;
        public event EventHandler HeaderMouseEnterForAWhileEvent;
        private DispatcherTimer _timer;

        public MainWindowTabItem()
        {
            InitializeComponent();
            this.HeaderMouseEnterTimerMilliseconds = 800;
            this._timer = new DispatcherTimer(DispatcherPriority.Send);
            this._timer.Tick += new EventHandler(timer_Tick);
            this._timer.Interval = new TimeSpan(0, 0, 0, 0, this.HeaderMouseEnterTimerMilliseconds);
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            this._timer.Stop();
            if (this.HeaderMouseEnterForAWhileEvent != null)
            {
                this.HeaderMouseEnterForAWhileEvent(this, new EventArgs());
                
            }
        }

        private void Border_MouseEnter(object sender, MouseEventArgs e)
        {
            this._timer.Start();
            if (this.HeaderMouseEnterEvent != null)
            {
                this.HeaderMouseEnterEvent(this, e);
            }
        }

        private void Border_MouseLeave(object sender, MouseEventArgs e)
        {
            this._timer.Stop();
            if (this.HeaderMouseLeaveEvent != null)
            {
                this.HeaderMouseLeaveEvent(this, e);
            }
        }

        private void TextBlock_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (this.PreviewHeaderMouseLeftButtonDownEvent != null)
            {
                this.PreviewHeaderMouseLeftButtonDownEvent(this, e);
            }
        }

    }
}
